<!DOCTYPE html>

<title>myapp</title>

<div>
  <h2>Canvas:<h2>
  <canvas id="canvas" width="256" height="256"></canvas>
</div>

<div>
  <h2>NES:<h2>
  <canvas id="nes" width="256" height="240"></canvas>
</div>

<script type="text/javascript" src="./nes.js"></script>

<script>
  let app = new WaApp();
  app.init().then((result) => {
    app.main();

    app.NES_InitGame();

    let preTimeStamp;
    let stepAnima = function (timeStamp) {
      // 转化为秒为单位
      if(timeStamp > 0) {
        timeStamp = timeStamp/1000;
      } else {
        timeStamp = 0;
      }

      // 记录当前时间
      if (!preTimeStamp) {
        preTimeStamp = timeStamp;
      }

      // 时间间隔
      let dt = timeStamp - preTimeStamp;
      console.log(`nes.html: dt = ${dt}`);

      // 执行
      app.NES_StepSeconds(dt);
      preTimeStamp = timeStamp;
      window.requestAnimationFrame(stepAnima);
    }
    window.requestAnimationFrame(stepAnima);
  })
</script>

